/*
https://leetcode-cn.com/problems/arithmetic-slices-ii-subsequence/solution/deng-chai-shu-lie-hua-fen-ii-zi-xu-lie-b-77pl/
 */
import java.util.HashMap;
import java.util.Map;

public class Solution446 {
    public int numberOfArithmeticSlices(int[] nums) {
        int ans=0;
        Map<Long,Integer>[] f=new Map[nums.length];
        for (int i=0;i<nums.length;i++){
            f[i]=new HashMap<>();
        }
        for (int i=0;i<nums.length;i++){
            for (int j=0;j<i;j++){
                long d=1L*nums[i]-nums[j];
                int t=f[j].getOrDefault(d,0);
                ans+=t;
                f[i].put(d,f[i].getOrDefault(d,0)+t+1);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution446().numberOfArithmeticSlices(new int[]{2,4,6,8,10}));
    }
}
